package com.zlzlib.common.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import java.io.IOException;

/**
 * jackson 将某字段总是转化为string
 * 字段增加注解  @JsonDeserialize(using = AlwaysStringDeserializer.class)
 *
 * @author 66453
 */
public class AlwaysStringDeserializer extends StdDeserializer<String> {

    protected AlwaysStringDeserializer() {
        this(null);
    }

    protected AlwaysStringDeserializer(Class<?> vc) {
        super(vc);
    }

    @Override
    public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        JsonNode node = p.getCodec().readTree(p);
        return node.toString();
    }
}